home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4367 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.3 KB  |  71 lines

  1. Path: strauss.udel.edu!not-for-mail
  2. From: jcorig@strauss.udel.edu (John Pat Corigliano)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: SasC linker Error:
  5. Date: 28 Feb 1996 01:49:03 -0500
  6. Organization: University of Delaware
  7. Message-ID: <4h0tsv$dsi@strauss.udel.edu>
  8. References: <dkauppDnEzzs.FsD@netcom.com> <758.6631T1348T796@sn.no>
  9. NNTP-Posting-Host: strauss.udel.edu
  10.  
  11. In article <758.6631T1348T796@sn.no>, Christopher Naas <christon@sn.no> wrote:
  12. >Blitter wrote:
  13. >
  14. >> Can someone tell me what may be causing these errors? MOBtrigger is a
  15. >>BOOL and as far a I know, its just changed using TRUE and FALSE.
  16. >
  17. >>ERROR: Multiply defined symbol '_MOBtrigger'.
  18. >>       First defined in file 'comm.o'.
  19. >>        Type = RELOCATABLE   Value = 1010
  20. >>       Redefined in file 'special.o'.
  21. >>        Type = RELOCATABLE   Value = 9
  22. >[..]
  23. >
  24. >You probably have a Global.h or such with "BOOL MOBTrigger = ..;" .. replace
  25. >this with "BOOL MOBTrigger;", and it should work.
  26.  
  27. No, that won't work.  A global variable can only be declared once.  The
  28. "=" doesn't matter since both are declarations.  You need to declare
  29. MOBTrigger in one file only. Any other files that use MOBTrigger need
  30. to define it as "extern".  So, in main.c you might have:
  31.    BOOL MOBTrigger = FALSE;
  32. And in some_other_file.c have:
  33.    extern BOOL MOBTrigger;
  34.  
  35. I like to use one header file that contains the declarations of all global
  36. variables.  The "trick" to doing this is to create a macro like so:
  37.  
  38. #ifdef MAIN_C
  39. #define Global
  40. #define Init(var, val) var = val
  41. #else
  42. #define Global extern
  43. #define Init(var, val) var
  44. #endif
  45.  
  46. Then you can declare your global variables like this:
  47.  
  48. Global int x;
  49. Global BOOL Init(flag, FALSE);
  50. etc...
  51.  
  52. If this file is called "vars.h", one file includes it like this:
  53.  
  54. #define MAIN_C
  55. #include "vars.h"
  56. #undef MAIN_C
  57.  
  58. And all other files simply #include "vars.h".
  59.  
  60. One implication to this is that the file that defines MAIN_C must
  61. be re-compiled whenever a new variable is added to "vars.h".  This
  62. is simply handled by adding "vars.h" to the dependency list of that
  63. file.
  64.  
  65. I hope someone finds this info useful :)
  66. -- 
  67. John Corigliano                                  jcorig@strauss.udel.edu
  68. Computer and Information Science                  University of Delaware
  69. --
  70. "Never drive a car when you're dead."  - Tom Waits
  71.